﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FingerTip.Infrastructure.MongoDb.Extensions
{
    public static class MongoDbQuerableExtensions
    {
            public static (List<T> Result, long Count) Page<T>(this IQueryable<T> query, int pageIndex = 0, int pageSize = 0) where T : IMongoDbEntityBase, new()
            {
                var count = query.Count<T>();
                if (pageIndex > 0 && pageSize > 0)
                {
                    query = query.Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                }
                var result = query.ToList();
                return (result, count);
            }

            public static (List<T> Result, long Count) Excute<T>(this IQueryable<T> query) where T : IMongoDbEntityBase, new()
            {
                var count = query.Count<T>();
                var result = query.ToList();
                return (result, count);
            }
    }
}
